package cn.edu.qut.edusys.controller;

import cn.edu.qut.edusys.mapper.UserMapper;
import cn.edu.qut.edusys.util.EmailUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    private UserMapper userMapper;
    @RequestMapping("/reg")
    public int reg(@RequestParam Map<String,String> param){
        int row = 0;
        System.out.println(param);
        row=userMapper.save(param);
        return row;
    }

    @RequestMapping("/reg1")
    public int reg1(@RequestParam Map<String,String> param){
        int row = 0;
        System.out.println(param);
        row=userMapper.saveRegister(param);
        return row;
    }


    //查找数据库
    @RequestMapping("/search")
    public List<Map<String,Object>> search(@RequestParam Map<String,String> param){
        List<Map<String,Object>> list=null;
        list=userMapper.search(param);
        return list;
    }
    @RequestMapping("/searchPhone")
    public List<Map<String,Object>> searchPhone(@RequestParam Map<String,String> param){
        List<Map<String,Object>> list;
        //System.out.println(param);
        list=userMapper.searchPhone(param);
        return list;
    }
    //增加记录
    @RequestMapping("/add")
    public int add(@RequestParam Map<String,String> param){
        int list;
        list=userMapper.add(param);
        return list;
    }
    //修改记录
    @RequestMapping("/change")
    public int change(@RequestParam Map<String,String> param){
        int list;
        list=userMapper.change(param);
        return list;
    }
    @RequestMapping("/delete")
    public int delete(@RequestParam Map<String,String> param){
        int list;
        list=userMapper.delete(param);
        return list;
    }
    @Resource
    private EmailUtil emailUtil;
    @RequestMapping("/email")
    public int email(@RequestParam Map<String,String> param){
        System.out.println(param);
        int row=0;
        row=emailUtil.sendMail(param.get("userEmail"));
        return row;
    }
    @RequestMapping("/changePassword")
    public int changePassword(@RequestParam Map<String,String> param){
        int list;
        list=userMapper.changePassword(param);
        return list;
    }
}
